#include "stdafx.h"
#include "Camera.h"

namespace PhotonMapping
{


Camera::Camera() 
	: m_Position(0.0f, 0.0f, -5.0f), m_Target(0.0f, 0.0f, 0.0f), m_Matrix(1.0f)
{
}

void Camera::SetPosition(const Math::Vector3& p_Position)
{
	m_Position = p_Position;
}

void Camera::SetTarget(const Math::Vector3& p_Target)
{
	m_Target = p_Target;
}

void Camera::UpdateMatrix()
{
	using namespace Math;

	// calculate camera matrix
	Vector3 zAxis = m_Target - m_Position;
	zAxis.Normalize();
	
	// we use UNIT_Y as the up vector (0, 1, 0)
	Vector3 xAxis = Cross(Vector3::UNIT_Y, zAxis);
	xAxis.Normalize();
	Vector3 yAxis = Cross(xAxis, -zAxis);
	yAxis.Normalize();
	
	m_Matrix.SetRow(0, Vector4(xAxis));
	m_Matrix.SetRow(1, Vector4(yAxis));
	m_Matrix.SetRow(2, Vector4(zAxis));
	m_Matrix.InvertTransformationMatrix();
	m_Matrix.SetCol(3, Vector4(m_Position, 1.0f));
}

const Math::Matrix4& Camera::GetMatrix() const
{
	return m_Matrix;
}


}
